<?php
namespace Common\Model;

use Think\Model;

class SystemStoreModel extends \BaseModel
{
    public function load($id)
    {
        $info = $this->find($id);
        return $info;
    }

    /*****用户id来查找商家**/
    public function ByUserId($id)
    {
        $info = BoxModel("system_store_user")->load($id);
        return $info;
    }

    /*****创建用户**/
    public function  create_store($data)
    {
        $store_user = BoxModel("system_store_user");
        $arr = $this->create($data);
        $arr['created'] = time();
        $row1 = array(
            'user_name' => $data['user_name'],
            'password' => encrypt($data['password']),
        );
        if ($store_id = $data['store_id']) {
            $this->where(array('store_id' => $store_id))->save($arr);
            $store_user->where(array('store_id' => $store_id, 'type' => 1))->save($row1);
        } else {
            $store_id = $this->add($arr);
            if ($store_id) {
                $row1['store_id'] = $store_id;
                $store_user->add($row1);
            }
        }

        return $store_id;
    }


}